package com.springboot.codeminestarter.proxy;

import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

public class ProxyHolder implements MethodInterceptor {
    @Override
    public Object intercept(Object o, Method method, Object[] args, MethodProxy methodProxy) {

        Object invoke = null;
        try {
            System.out.println("Before method invocation: " + method.getName());
            invoke = methodProxy.invokeSuper(o, args);
            System.out.println("After method invocation: " + method.getName());
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        return invoke;
    }
}
